package com.me.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.me.dao.PaperQuestionDAO;
import com.me.entity.PaperQuestion;

/**
 * 试卷问答题绑定表
 * @author dong
 */
@Service
public class PaperQuestionService extends BaseService<PaperQuestion, PaperQuestionDAO> {
	/**
	 * 注入持久层组件
	 */
	@Resource
	private PaperQuestionDAO paperQuestionDAO;
	
	@Override
	protected PaperQuestionDAO getDao() {
		return paperQuestionDAO;
	}
	
	/**
	 * 根据试卷编号和选择题编号查找唯一一条记录
	 */
	public PaperQuestion findOne(Integer paperId, Integer quesId){
		PaperQuestion paperQuestion = new PaperQuestion();
		paperQuestion.setPaperId(paperId);
		paperQuestion.setQuestionId(quesId);
		return paperQuestionDAO.queryByPaperIdAndQuesId(paperQuestion);
	}
	
	/**
	 * 根据试卷编号查找记录
	 */
	public List<PaperQuestion> queryByPaperId(Integer paperId){
		PaperQuestion paperQuestion = new PaperQuestion();
		paperQuestion.setPaperId(paperId);
		return paperQuestionDAO.preciseQuery(paperQuestion);
	}
	
	/**
	 * 新增一条绑定记录
	 */
	public void insertBind(Integer paperId, Integer quesId) throws Exception{
		PaperQuestion paperQuestion = new PaperQuestion();
		paperQuestion.setPaperId(paperId);
		paperQuestion.setQuestionId(quesId);
		paperQuestionDAO.insert(paperQuestion);
	}
	
	/**
	 * 更新绑定记录中的考生答案
	 */
	public void updateAnswer(PaperQuestion paperQuestion) throws Exception{
		Assert.notNull(paperQuestion);
		Assert.notNull(paperQuestion.getId());
		paperQuestionDAO.update(paperQuestion);
	}
}
